#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2011 thomasv@gitorious
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.



# list of words from http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/Contemporary_poetry

words = [
"like",
"just",
"love",
"know",
"never",
"want",
"time",
"out",
"there",
"make",
"look",
"eye",
"down",
"only",
"think",
"heart",
"back",
"then",
"into",
"about",
"more",
"away",
"still",
"them",
"take",
"thing",
"even",
"through",
"long",
"always",
"world",
"too",
"friend",
"tell",
"try",
"hand",
"thought",
"over",
"here",
"other",
"need",
"smile",
"again",
"much",
"cry",
"been",
"night",
"ever",
"little",
"said",
"end",
"some",
"those",
"around",
"mind",
"people",
"girl",
"leave",
"dream",
"left",
"turn",
"myself",
"give",
"nothing",
"really",
"off",
"before",
"something",
"find",
"walk",
"wish",
"good",
"once",
"place",
"ask",
"stop",
"keep",
"watch",
"seem",
"everything",
"wait",
"got",
"yet",
"made",
"remember",
"start",
"alone",
"run",
"hope",
"maybe",
"believe",
"body",
"hate",
"after",
"close",
"talk",
"stand",
"own",
"each",
"hurt",
"help",
"home",
"god",
"soul",
"new",
"many",
"two",
"inside",
"should",
"true",
"first",
"fear",
"mean",
"better",
"play",
"another",
"gone",
"change",
"use",
"wonder",
"someone",
"hair",
"cold",
"open",
"best",
"any",
"behind",
"happen",
"water",
"dark",
"laugh",
"stay",
"forever",
"name",
"work",
"show",
"sky",
"break",
"came",
"deep",
"door",
"put",
"black",
"together",
"upon",
"happy",
"such",
"great",
"white",
"matter",
"fill",
"past",
"please",
"burn",
"cause",
"enough",
"touch",
"moment",
"soon",
"voice",
"scream",
"anything",
"stare",
"sound",
"red",
"everyone",
"hide",
"kiss",
"truth",
"death",
"beautiful",
"mine",
"blood",
"broken",
"very",
"pass",
"next",
"forget",
"tree",
"wrong",
"air",
"mother",
"understand",
"lip",
"hit",
"wall",
"memory",
"sleep",
"free",
"high",
"realize",
"school",
"might",
"skin",
"sweet",
"perfect",
"blue",
"kill",
"breath",
"dance",
"against",
"fly",
"between",
"grow",
"strong",
"under",
"listen",
"bring",
"sometimes",
"speak",
"pull",
"person",
"become",
"family",
"begin",
"ground",
"real",
"small",
"father",
"sure",
"feet",
"rest",
"young",
"finally",
"land",
"across",
"today",
"different",
"guy",
"line",
"fire",
"reason",
"reach",
"second",
"slowly",
"write",
"eat",
"smell",
"mouth",
"step",
"learn",
"three",
"floor",
"promise",
"breathe",
"darkness",
"push",
"earth",
"guess",
"save",
"song",
"above",
"along",
"both",
"color",
"house",
"almost",
"sorry",
"anymore",
"brother",
"okay",
"dear",
"game",
"fade",
"already",
"apart",
"warm",
"beauty",
"heard",
"notice",
"question",
"shine",
"began",
"piece",
"whole",
"shadow",
"secret",
"street",
"within",
"finger",
"point",
"morning",
"whisper",
"child",
"moon",
"green",
"story",
"glass",
"kid",
"silence",
"since",
"soft",
"yourself",
"empty",
"shall",
"angel",
"answer",
"baby",
"bright",
"dad",
"path",
"worry",
"hour",
"drop",
"follow",
"power",
"war",
"half",
"flow",
"heaven",
"act",
"chance",
"fact",
"least",
"tired",
"children",
"near",
"quite",
"afraid",
"rise",
"sea",
"taste",
"window",
"cover",
"nice",
"trust",
"lot",
"sad",
"cool",
"force",
"peace",
"return",
"blind",
"easy",
"ready",
"roll",
"rose",
"drive",
"held",
"music",
"beneath",
"hang",
"mom",
"paint",
"emotion",
"quiet",
"clear",
"cloud",
"few",
"pretty",
"bird",
"outside",
"paper",
"picture",
"front",
"rock",
"simple",
"anyone",
"meant",
"reality",
"road",
"sense",
"waste",
"bit",
"leaf",
"thank",
"happiness",
"meet",
"men",
"smoke",
"truly",
"decide",
"self",
"age",
"book",
"form",
"alive",
"carry",
"escape",
"damn",
"instead",
"able",
"ice",
"minute",
"throw",
"catch",
"leg",
"ring",
"course",
"goodbye",
"lead",
"poem",
"sick",
"corner",
"desire",
"known",
"problem",
"remind",
"shoulder",
"suppose",
"toward",
"wave",
"drink",
"jump",
"woman",
"pretend",
"sister",
"week",
"human",
"joy",
"crack",
"grey",
"pray",
"surprise",
"dry",
"knee",
"less",
"search",
"bleed",
"caught",
"clean",
"embrace",
"future",
"king",
"son",
"sorrow",
"chest",
"hug",
"remain",
"sat",
"worth",
"blow",
"daddy",
"final",
"parent",
"tight",
"also",
"create",
"lonely",
"safe",
"cross",
"dress",
"evil",
"silent",
"bone",
"fate",
"perhaps",
"anger",
"class",
"scar",
"snow",
"tiny",
"tonight",
"continue",
"control",
"dog",
"edge",
"mirror",
"month",
"suddenly",
"comfort",
"given",
"loud",
"quickly",
"gaze",
"plan",
"rush",
"stone",
"town",
"battle",
"ignore",
"spirit",
"stood",
"stupid",
"yours",
"brown",
"build",
"dust",
"hey",
"kept",
"pay",
"phone",
"twist",
"although",
"ball",
"beyond",
"hidden",
"nose",
"taken",
"fail",
"float",
"pure",
"somehow",
"wash",
"wrap",
"angry",
"cheek",
"creature",
"forgotten",
"heat",
"rip",
"single",
"space",
"special",
"weak",
"whatever",
"yell",
"anyway",
"blame",
"job",
"choose",
"country",
"curse",
"drift",
"echo",
"figure",
"grew",
"laughter",
"neck",
"suffer",
"worse",
"yeah",
"disappear",
"foot",
"forward",
"knife",
"mess",
"somewhere",
"stomach",
"storm",
"beg",
"idea",
"lift",
"offer",
"breeze",
"field",
"five",
"often",
"simply",
"stuck",
"win",
"allow",
"confuse",
"enjoy",
"except",
"flower",
"seek",
"strength",
"calm",
"grin",
"gun",
"heavy",
"hill",
"large",
"ocean",
"shoe",
"sigh",
"straight",
"summer",
"tongue",
"accept",
"crazy",
"everyday",
"exist",
"grass",
"mistake",
"sent",
"shut",
"surround",
"table",
"ache",
"brain",
"destroy",
"heal",
"nature",
"shout",
"sign",
"stain",
"choice",
"doubt",
"glance",
"glow",
"mountain",
"queen",
"stranger",
"throat",
"tomorrow",
"city",
"either",
"fish",
"flame",
"rather",
"shape",
"spin",
"spread",
"ash",
"distance",
"finish",
"image",
"imagine",
"important",
"nobody",
"shatter",
"warmth",
"became",
"feed",
"flesh",
"funny",
"lust",
"shirt",
"trouble",
"yellow",
"attention",
"bare",
"bite",
"money",
"protect",
"amaze",
"appear",
"born",
"choke",
"completely",
"daughter",
"fresh",
"friendship",
"gentle",
"probably",
"six",
"deserve",
"expect",
"grab",
"middle",
"nightmare",
"river",
"thousand",
"weight",
"worst",
"wound",
"barely",
"bottle",
"cream",
"regret",
"relationship",
"stick",
"test",
"crush",
"endless",
"fault",
"itself",
"rule",
"spill",
"art",
"circle",
"join",
"kick",
"mask",
"master",
"passion",
"quick",
"raise",
"smooth",
"unless",
"wander",
"actually",
"broke",
"chair",
"deal",
"favorite",
"gift",
"note",
"number",
"sweat",
"box",
"chill",
"clothes",
"lady",
"mark",
"park",
"poor",
"sadness",
"tie",
"animal",
"belong",
"brush",
"consume",
"dawn",
"forest",
"innocent",
"pen",
"pride",
"stream",
"thick",
"clay",
"complete",
"count",
"draw",
"faith",
"press",
"silver",
"struggle",
"surface",
"taught",
"teach",
"wet",
"bless",
"chase",
"climb",
"enter",
"letter",
"melt",
"metal",
"movie",
"stretch",
"swing",
"vision",
"wife",
"beside",
"crash",
"forgot",
"guide",
"haunt",
"joke",
"knock",
"plant",
"pour",
"prove",
"reveal",
"steal",
"stuff",
"trip",
"wood",
"wrist",
"bother",
"bottom",
"crawl",
"crowd",
"fix",
"forgive",
"frown",
"grace",
"loose",
"lucky",
"party",
"release",
"surely",
"survive",
"teacher",
"gently",
"grip",
"speed",
"suicide",
"travel",
"treat",
"vein",
"written",
"cage",
"chain",
"conversation",
"date",
"enemy",
"however",
"interest",
"million",
"page",
"pink",
"proud",
"sway",
"themselves",
"winter",
"church",
"cruel",
"cup",
"demon",
"experience",
"freedom",
"pair",
"pop",
"purpose",
"respect",
"shoot",
"softly",
"state",
"strange",
"bar",
"birth",
"curl",
"dirt",
"excuse",
"lord",
"lovely",
"monster",
"order",
"pack",
"pants",
"pool",
"scene",
"seven",
"shame",
"slide",
"ugly",
"among",
"blade",
"blonde",
"closet",
"creek",
"deny",
"drug",
"eternity",
"gain",
"grade",
"handle",
"key",
"linger",
"pale",
"prepare",
"swallow",
"swim",
"tremble",
"wheel",
"won",
"cast",
"cigarette",
"claim",
"college",
"direction",
"dirty",
"gather",
"ghost",
"hundred",
"loss",
"lung",
"orange",
"present",
"swear",
"swirl",
"twice",
"wild",
"bitter",
"blanket",
"doctor",
"everywhere",
"flash",
"grown",
"knowledge",
"numb",
"pressure",
"radio",
"repeat",
"ruin",
"spend",
"unknown",
"buy",
"clock",
"devil",
"early",
"false",
"fantasy",
"pound",
"precious",
"refuse",
"sheet",
"teeth",
"welcome",
"add",
"ahead",
"block",
"bury",
"caress",
"content",
"depth",
"despite",
"distant",
"marry",
"purple",
"threw",
"whenever",
"bomb",
"dull",
"easily",
"grasp",
"hospital",
"innocence",
"normal",
"receive",
"reply",
"rhyme",
"shade",
"someday",
"sword",
"toe",
"visit",
"asleep",
"bought",
"center",
"consider",
"flat",
"hero",
"history",
"ink",
"insane",
"muscle",
"mystery",
"pocket",
"reflection",
"shove",
"silently",
"smart",
"soldier",
"spot",
"stress",
"train",
"type",
"view",
"whether",
"bus",
"energy",
"explain",
"holy",
"hunger",
"inch",
"magic",
"mix",
"noise",
"nowhere",
"prayer",
"presence",
"shock",
"snap",
"spider",
"study",
"thunder",
"trail",
"admit",
"agree",
"bag",
"bang",
"bound",
"butterfly",
"cute",
"exactly",
"explode",
"familiar",
"fold",
"further",
"pierce",
"reflect",
"scent",
"selfish",
"sharp",
"sink",
"spring",
"stumble",
"universe",
"weep",
"women",
"wonderful",
"action",
"ancient",
"attempt",
"avoid",
"birthday",
"branch",
"chocolate",
"core",
"depress",
"drunk",
"especially",
"focus",
"fruit",
"honest",
"match",
"palm",
"perfectly",
"pillow",
"pity",
"poison",
"roar",
"shift",
"slightly",
"thump",
"truck",
"tune",
"twenty",
"unable",
"wipe",
"wrote",
"coat",
"constant",
"dinner",
"drove",
"egg",
"eternal",
"flight",
"flood",
"frame",
"freak",
"gasp",
"glad",
"hollow",
"motion",
"peer",
"plastic",
"root",
"screen",
"season",
"sting",
"strike",
"team",
"unlike",
"victim",
"volume",
"warn",
"weird",
"attack",
"await",
"awake",
"built",
"charm",
"crave",
"despair",
"fought",
"grant",
"grief",
"horse",
"limit",
"message",
"ripple",
"sanity",
"scatter",
"serve",
"split",
"string",
"trick",
"annoy",
"blur",
"boat",
"brave",
"clearly",
"cling",
"connect",
"fist",
"forth",
"imagination",
"iron",
"jock",
"judge",
"lesson",
"milk",
"misery",
"nail",
"naked",
"ourselves",
"poet",
"possible",
"princess",
"sail",
"size",
"snake",
"society",
"stroke",
"torture",
"toss",
"trace",
"wise",
"bloom",
"bullet",
"cell",
"check",
"cost",
"darling",
"during",
"footstep",
"fragile",
"hallway",
"hardly",
"horizon",
"invisible",
"journey",
"midnight",
"mud",
"nod",
"pause",
"relax",
"shiver",
"sudden",
"value",
"youth",
"abuse",
"admire",
"blink",
"breast",
"bruise",
"constantly",
"couple",
"creep",
"curve",
"difference",
"dumb",
"emptiness",
"gotta",
"honor",
"plain",
"planet",
"recall",
"rub",
"ship",
"slam",
"soar",
"somebody",
"tightly",
"weather",
"adore",
"approach",
"bond",
"bread",
"burst",
"candle",
"coffee",
"cousin",
"crime",
"desert",
"flutter",
"frozen",
"grand",
"heel",
"hello",
"language",
"level",
"movement",
"pleasure",
"powerful",
"random",
"rhythm",
"settle",
"silly",
"slap",
"sort",
"spoken",
"steel",
"threaten",
"tumble",
"upset",
"aside",
"awkward",
"bee",
"blank",
"board",
"button",
"card",
"carefully",
"complain",
"crap",
"deeply",
"discover",
"drag",
"dread",
"effort",
"entire",
"fairy",
"giant",
"gotten",
"greet",
"illusion",
"jeans",
"leap",
"liquid",
"march",
"mend",
"nervous",
"nine",
"replace",
"rope",
"spine",
"stole",
"terror",
"accident",
"apple",
"balance",
"boom",
"childhood",
"collect",
"demand",
"depression",
"eventually",
"faint",
"glare",
"goal",
"group",
"honey",
"kitchen",
"laid",
"limb",
"machine",
"mere",
"mold",
"murder",
"nerve",
"painful",
"poetry",
"prince",
"rabbit",
"shelter",
"shore",
"shower",
"soothe",
"stair",
"steady",
"sunlight",
"tangle",
"tease",
"treasure",
"uncle",
"begun",
"bliss",
"canvas",
"cheer",
"claw",
"clutch",
"commit",
"crimson",
"crystal",
"delight",
"doll",
"existence",
"express",
"fog",
"football",
"gay",
"goose",
"guard",
"hatred",
"illuminate",
"mass",
"math",
"mourn",
"rich",
"rough",
"skip",
"stir",
"student",
"style",
"support",
"thorn",
"tough",
"yard",
"yearn",
"yesterday",
"advice",
"appreciate",
"autumn",
"bank",
"beam",
"bowl",
"capture",
"carve",
"collapse",
"confusion",
"creation",
"dove",
"feather",
"girlfriend",
"glory",
"government",
"harsh",
"hop",
"inner",
"loser",
"moonlight",
"neighbor",
"neither",
"peach",
"pig",
"praise",
"screw",
"shield",
"shimmer",
"sneak",
"stab",
"subject",
"throughout",
"thrown",
"tower",
"twirl",
"wow",
"army",
"arrive",
"bathroom",
"bump",
"cease",
"cookie",
"couch",
"courage",
"dim",
"guilt",
"howl",
"hum",
"husband",
"insult",
"led",
"lunch",
"mock",
"mostly",
"natural",
"nearly",
"needle",
"nerd",
"peaceful",
"perfection",
"pile",
"price",
"remove",
"roam",
"sanctuary",
"serious",
"shiny",
"shook",
"sob",
"stolen",
"tap",
"vain",
"void",
"warrior",
"wrinkle",
"affection",
"apologize",
"blossom",
"bounce",
"bridge",
"cheap",
"crumble",
"decision",
"descend",
"desperately",
"dig",
"dot",
"flip",
"frighten",
"heartbeat",
"huge",
"lazy",
"lick",
"odd",
"opinion",
"process",
"puzzle",
"quietly",
"retreat",
"score",
"sentence",
"separate",
"situation",
"skill",
"soak",
"square",
"stray",
"taint",
"task",
"tide",
"underneath",
"veil",
"whistle",
"anywhere",
"bedroom",
"bid",
"bloody",
"burden",
"careful",
"compare",
"concern",
"curtain",
"decay",
"defeat",
"describe",
"double",
"dreamer",
"driver",
"dwell",
"evening",
"flare",
"flicker",
"grandma",
"guitar",
"harm",
"horrible",
"hungry",
"indeed",
"lace",
"melody",
"monkey",
"nation",
"object",
"obviously",
"rainbow",
"salt",
"scratch",
"shown",
"shy",
"stage",
"stun",
"third",
"tickle",
"useless",
"weakness",
"worship",
"worthless",
"afternoon",
"beard",
"boyfriend",
"bubble",
"busy",
"certain",
"chin",
"concrete",
"desk",
"diamond",
"doom",
"drawn",
"due",
"felicity",
"freeze",
"frost",
"garden",
"glide",
"harmony",
"hopefully",
"hunt",
"jealous",
"lightning",
"mama",
"mercy",
"peel",
"physical",
"position",
"pulse",
"punch",
"quit",
"rant",
"respond",
"salty",
"sane",
"satisfy",
"savior",
"sheep",
"slept",
"social",
"sport",
"tuck",
"utter",
"valley",
"wolf",
"aim",
"alas",
"alter",
"arrow",
"awaken",
"beaten",
"belief",
"brand",
"ceiling",
"cheese",
"clue",
"confidence",
"connection",
"daily",
"disguise",
"eager",
"erase",
"essence",
"everytime",
"expression",
"fan",
"flag",
"flirt",
"foul",
"fur",
"giggle",
"glorious",
"ignorance",
"law",
"lifeless",
"measure",
"mighty",
"muse",
"north",
"opposite",
"paradise",
"patience",
"patient",
"pencil",
"petal",
"plate",
"ponder",
"possibly",
"practice",
"slice",
"spell",
"stock",
"strife",
"strip",
"suffocate",
"suit",
"tender",
"tool",
"trade",
"velvet",
"verse",
"waist",
"witch",
"aunt",
"bench",
"bold",
"cap",
"certainly",
"click",
"companion",
"creator",
"dart",
"delicate",
"determine",
"dish",
"dragon",
"drama",
"drum",
"dude",
"everybody",
"feast",
"forehead",
"former",
"fright",
"fully",
"gas",
"hook",
"hurl",
"invite",
"juice",
"manage",
"moral",
"possess",
"raw",
"rebel",
"royal",
"scale",
"scary",
"several",
"slight",
"stubborn",
"swell",
"talent",
"tea",
"terrible",
"thread",
"torment",
"trickle",
"usually",
"vast",
"violence",
"weave",
"acid",
"agony",
"ashamed",
"awe",
"belly",
"blend",
"blush",
"character",
"cheat",
"common",
"company",
"coward",
"creak",
"danger",
"deadly",
"defense",
"define",
"depend",
"desperate",
"destination",
"dew",
"duck",
"dusty",
"embarrass",
"engine",
"example",
"explore",
"foe",
"freely",
"frustrate",
"generation",
"glove",
"guilty",
"health",
"hurry",
"idiot",
"impossible",
"inhale",
"jaw",
"kingdom",
"mention",
"mist",
"moan",
"mumble",
"mutter",
"observe",
"ode",
"pathetic",
"pattern",
"pie",
"prefer",
"puff",
"rape",
"rare",
"revenge",
"rude",
"scrape",
"spiral",
"squeeze",
"strain",
"sunset",
"suspend",
"sympathy",
"thigh",
"throne",
"total",
"unseen",
"weapon",
"weary"
]

n = 1626
Chinese = '''
乾坤有序宇宙无疆星辰密布斗柄指航
昼白夜黑日明月亮风驰雪舞电闪雷响
云腾致雨露结晨霜虹霓霞辉雾沉雹降
春生夏长秋收冬藏时令应候寒来暑往
远古洪荒海田沧桑陆地漂移板块碰撞
山岳巍峨湖泊荡漾植被旷野岛撒汪洋
冰川冻土沙漠沃壤木丰树森岩多滩广
鸟飞兽走鳞潜羽翔境态和谐物种安详
形分上下道合阴阳幽冥杳渺天体著彰
凝气为精聚能以场缩浓而质积微显量
化巨幻虚恍惚成象强固凌弱柔亦制刚
终极必反存兴趋亡色空轮回动静恒常
唯实众名一理万方父母爹娘没齿难忘
兄弟姐妹危困助帮姑姨叔舅亲戚互访
侄男闺少哺育茁壮夫妻相敬梦忆糟糠
隔屋邻舍遇事谦谅伯公妪婆慈孝赡养
尊朋礼友仁义君郎炎黄二帝尧舜禅让
禹启世袭灭桀商汤周武伐纣侯列各邦
秦皇集权汉刘楚项鼎立割据乱晋八王
南北对峙腐朽隋炀贞观政要五代续唐
陈桥兵变耻辱靖康耶律完颜元建宋僵
钟离太祖崇祯吊丧清军入关大臣驻藏
粉碎叛卓犁域设将台湾复归守卫边防
鸦片战争英占香港戊戌维新社会改良
辛亥革命孙文思想联盟抗倭国共两党
定都京师人民解放诸子百家孔孟老庄
扁鹊灵医鲁班巧匠罗盘硝药针灸疗伤
蔡伦毕升鉴真玄奘易经论语史记达畅
河图洛书算术九章西三红水聊儒瓶厢
诗词曲赋戏剧说唱琵琶琴瑟锣镲铿锵
笙箫呜咽卧笛悠扬筝音奔奋唢呐高亢
荆浩匡庐董源潇湘米芾写意悲鸿骏昂
笔墨纸砚匾楣楹榜楷隶篆刻碑帖草狂
敦煌石窟长城伟墙青铜甲骨缕衣纱裳
虎符越剑陶马俑葬彩瓷宝瓮丝绸他乡
凡尔赛宫金字塔状泰姬陵墓彼得教堂
自由女神希腊塑像最后晚餐创造亚当
亭榭楼阁寺庙殿廊蓬门荜户丈室绿窗
府弟别墅画栋雕梁庭院踏步影屏幕障
承尘藻井篱笆柱桩舷舵扶靠凭栏眺望
悬崖峭壁峰峦叠嶂泉喷岚罩湍急瀑宕
峡沟潭渊溪涧流淌池渠堰坝沼泽泥塘
漩涡带波礁屿连江汹涌澎湃惊涛骇浪
灾涝溢泻汛潮浮涨苍松寿柏垂柳毛杨
芭蕉蒲扇斑竹篾筐槐椿榆桦杉桂榕樟
斋扉紧闭栅苑濒旁坪埔莱茵菲窥坞坊
蔷薇翩跹莆菏蔚茫蕴蒂荚芯蓓蕾琳琅
奇花异卉艳丽荣秧兰荷菊梅四季芬芳
杜鹃泣血芙蓉吉祥茉莉馥郁玫瑰刺芒
瓜果蔬菜葱蒜韭姜茴椒芹葵皮芥辣酱
芸苔芋笋葫芦瓢瓤番茄蘑菇乳蛋醇酿
碘盐食醋脆卜甜糖珍馐旨甘肴馔膏粱
葡萄美酒玉液琼浆咖啡益智茗茶顺肠
桃李杏柿汁鲜味爽椰柚橙桔渴饮品尝
菠萝柑橘橄榄槟榔梨枣苹楂荔栗榴棠
蝌蚪摆尾蛤蟆鼓囊钓饵蚯蚓蠕虫蚂蟥
鹦鹉学舌蜜蜂穿忙蝙蝠栖洞梧桐引凰
蜘蛛牵补螟蛉蛀粮蜻蜓振翅鸠鹏张膀
鸥莺燕雀蝴蝶鸳鸯鲤鲫鲇鲸蛙蚌螺螃
蚜蛾蝉蛹龟卵翼蝗蚊蝇鼠蚁蛇蝎鳝蟒
蜈蚣毒腺蟋蟀蹬闯鹿狈狐狸熊豹豺狼
猿啼猴吱鸵孵獭躺雏猩攀梢雌牡匿冈
砂舟骆驼迅捷羚羊中华初繁睡狮渐醒
玖久纪末千年始零宏业昌盛妙策递迎
左右兼顾总揽统领内取稳进外交志同
阶梯过度切忌狠猛六贼七害监视审听
戒贪须效践约宜行贬恶褒绩赏劝罚惩
操刃执斧塞涓救荧势如突起抽薪熄平
途逢险兆消芽于萌调息止纷贵在用衡
依法谋治官吏皆正推贤荐材睹貌辨容
纯朴宽厚侠烈尽忠耿直肃仪襟怀袒诚
谄媚狡猾机敏慧颖懈怠懒惰拙笨碌庸
愚昧糊涂偏才至聪羞涩拘束杰健悍雄
恭谨畏惧缄默持重骄奢傲慢怯懦惶恐
超逸独居恬淡匀宁猜疑诡秘威严毅勇
币帛钱钞攘夺其宗企财盼利价值均等
务工开厂增富减穷资产累计税率加乘
银行贷款储蓄倍宠抵押拆借循例不停
供给需求市货充盈销售买卖亏差余剩
债券股票博赌输赢闻赚虽喜跌赔癫疯
休闲退优涣虑受逍拒宾疏客忧谢欢招
把盏讲趣倚床读晓游景筏渡迹绝喧嚣
茂冠蔽枝莽园出条碧岭滴翠落叶飘摇
敞释矛盾剖层剥茧淀滤猖浊昭划界限
妨碍侦察贿赂仕宦诅咒吓唬挑衅侮谩
讥讽诽谤浑噩撤验朦胧伎俩仍留隙嫌
斟酌掺谎包庇捂瞒陨堕棘阱殃及祠眷
检举查封逮捕魁顽作奸犯科缉拿协办
妖魔鬼怪凶煞酷阎歹徒坏类狰狞嘴脸
勒逼豪阔搜刮卑贱拐架孩提坑蒙孕残
盗匪劫窃敲诈欺骗唆使怂勇横征暴敛
烧杀抢掠栽赃诬陷宰虐淫霸痞劣刁蛮
狎昵娼妓蹂躏鬓鬟猥亵妇寡屠戮毙斩
氓绅诱瘾倒置昏暗婢奴躲避怨斥责谴
酗殴滋祸弊秽泛滥偷漏假冒妄贩募捐
剃囚拷问傀儡敷衍侥幸饶恕期告赦免
镣铐锒铛忏悔已憾匆慌失措徐踱圃团
踌躇徘徊彷徨怖添窘焦愁绪沦颓苟喘
虱蚤蛆蛔茅厕臭便钾钠钙铝锌钢锡铅
镍锑锗钨铬钡铂钒硼汞硅硫苯氰锰碳
氯氢氦氟烯烃炔烷砒砷硒矽酚酞酮醛
腔膛脏腑脾肾髓胆唇嗓喉咙颐臆腹腆
肛胯脐趾膝颅眶睑肪膘冗赘颧颊骸嵌
'''
Chinese = Chinese.replace('\n','')
from binascii import hexlify,unhexlify

class Mnemonics:

    def __init__(self,message):
        self.message = message
        if isinstance(message,bytes):
            self.hex_message = hexlify(message).decode()
        else:
            self.hex_message = message
        self.chinese = []
        self.english = []
        self.encode()
        
    def encode(self):
        mes_len = len(self.hex_message)
        for i in range(mes_len//8):
            word = self.hex_message[8*i:8*i+8]
            x = int(word, 16)
            w1 = (x%n)
            w2 = ((x//n) + w1)%n
            w3 = ((x//n//n) + w2)%n
            self.english += [words[w1], words[w2], words[w3]]
            self.chinese += [Chinese[w1],Chinese[w2],Chinese[w3]]

    @staticmethod
    def decode_from_english(wlist):
        out = ''
        for i in range(len(wlist)//3):
            word1, word2, word3 = wlist[3*i:3*i+3]
            w1 =  words.index(word1)
            w2 = (words.index(word2))%n
            w3 = (words.index(word3))%n
            x = w1 +n*((w2-w1)%n) +n*n*((w3-w2)%n)
            out += '%08x'%x
        
        return unhexlify(out)

    @staticmethod
    def decode_from_chinese(wlist):
        out = ''
        elist = []
        for word in wlist:
            idx = Chinese.index(word)
            elist.append(words[idx])
            
        for i in range(len(elist)//3):
            word1, word2, word3 = elist[3*i:3*i+3]
            w1 =  words.index(word1)
            w2 = (words.index(word2))%n
            w3 = (words.index(word3))%n
            x = w1 +n*((w2-w1)%n) +n*n*((w3-w2)%n)
            out += '%08x'%x
        
        return unhexlify(out)
if __name__ == '__main__':
    import os
    import binascii
    hex_seed_256 = os.urandom(32)
    m = Mnemonics(hex_seed_256)
    
    

